import 'package:flutter/material.dart';
import 'package:pabu/widget/component/material/checkbox/checkbox_page.dart';
import 'package:pabu/widget/component/material/datatable/datatable_page.dart';
import 'package:pabu/widget/component/material/drawer/drawer_page.dart';
import 'package:pabu/widget/component/material/floating_action_button/floating_action_button_page.dart';
import 'package:pabu/widget/component/material/radio/radio_page.dart';
import 'package:pabu/widget/component/material/textfield/textfield_page.dart';

class MaterialPage extends StatefulWidget {
  @override
  _MaterialPageState createState() => new _MaterialPageState();
}

class _MaterialPageState extends State<MaterialPage> {
  @override
  Widget build(BuildContext context) {
    return _buildListView();
  }

  Widget _buildListView() {
    return ListView.builder(
      itemBuilder: (context, index) {
        return _buildListViewItem(index);
      },
      itemCount: components.length,
    );
  }

  Widget _buildListViewItem(index) {
    return GestureDetector(
      child: Container(
        padding: EdgeInsets.all(15.0),
        decoration: BoxDecoration(
            border: Border(bottom: BorderSide(color: Colors.white70))),
        child: Column(
          children: <Widget>[
            Container(
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Container(
                    child: Row(
                      children: <Widget>[
                        Text(components[index].name),
                      ],
                    ),
                  ),
                  Container(
                    child: Icon(Icons.arrow_forward_ios),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
      onTap: () {
        _pushPage(index);
      },
    );
  }

  void _pushPage(index) {
    Navigator.push(
      context,
      new MaterialPageRoute(builder: (context) => components[index].page),
    );
  }


}

class Component {
  Component({this.ukId, this.name, this.page});

  String ukId;
  String name;
  Widget page;
}

List<Component> components = <Component>[
  Component(ukId: "1", name: "Drawer", page: new DrawerPage()),
  Component(ukId: "2", name: "FloatingActionButton", page: new FloatingActionButtonPage()),
  Component(ukId: "3", name: "TextField", page: new TextFieldPage()),
  Component(ukId: "4", name: "Checkbox", page: new CheckboxPage()),
  Component(ukId: "5", name: "Radio", page: new RadioPage()),
  Component(ukId: "6", name: "DataTable", page: new DataTablePage()),
];
